Exercises

Hello world

Most introduction to programming session start with a Hello World example.

The gray cell below is what is called a code-cell. You can execute it by clicking on it and pressing ctrl+enter. Alternately you can find the button that looks like the "Play"-symbol in the toolbar above.


In [ ]:
print("Hello World!")

The system that creates this webpage is called Jupyter Notebooks. It is a language-independent system for displaying program code on a webpage, running the code in a server environment and displaying the output of the system to the user.

The exercises here will be conducted in Python 3, but the system supports multiple other languages. The purpose of having this very simple introduction early on is to make sure everyone is able to access their environment.

Go ahead and make your own Hello World below.


In [ ]:

Using the interactive interpreter

When working in the command line the interactive IPython interpreter can sometimes be more convenient than Jupyter notebook. Launch a terminal using the "New" -> "Terminal" functionality and start IPython by typing ipython in the terminal. Execute print("Hello") in the interactive interpreter. You can exit the interactive interpreter with the quit command

Working with Python scripts

In larger problems one typical writes the Python code in one or multiple .py files. In the terminal opened above create a file hello.py (use e.g. the nano texteditor) and place a proper print function there. After saving the file and exiting the editor execute the script with python hello.py.

Extra: calculator

You can use Python as a simple calculator. Try it out below if you have time.

Try to figure out (or google) how to do exponentiation, e.g. $2^5$.


In [ ]: